<?php

namespace App\Console\Commands;


use App\Helpers\Curl;
use App\Helpers\DateUtils;
use App\Helpers\Logger\SLogger;
use App\Models\Orm\CoinMarket;
use App\Models\Orm\CoinStoreLog;
use App\Models\Orm\UserCoinLog;
use Illuminate\Console\Command;
use DB;

class DelCoinOrder extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'DelCoinOrder';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '删除过期的订单';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

                $time = date('Y-m-d H:i:s',strtotime('-30minute'));

                DB::beginTransaction();
                try {
                    CoinStoreLog::where('status',CoinStoreLog::IGNORE)->where('created_at','<',$time)->delete();
                    UserCoinLog::where('status',CoinStoreLog::IGNORE)->where('created_at','<',$time)->delete();
                    SLogger::getStream()->info("删除订单成功");
                    DB::commit();
                } catch (\Exception $e) {

                    SLogger::getStream()->info("删除订单失败");
                    SLogger::getStream()->info($e);
                    DB::rollBack();
                }




    }
}
